//
//  PhoneNumViewController.m
//  WBBaseProject
//
//  Created by 吴斌 on 2018/3/20.
//  Copyright © 2018年 吴斌. All rights reserved.
//

#import "PhoneNumViewController.h"
#import "SettingCell.h"
#import "ReplacePhoneViewController.h"
static NSString * const SettingCellReuseId = @"SettingCell";

@interface PhoneNumViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;

@end

@implementation PhoneNumViewController

#pragma mark - 生命周期 Life Circle
- (void)viewDidLoad {
    [super viewDidLoad];  
    [self.view addSubview:self.tableView];
    self.navigationItem.title = @"手机号";
    [self registerCell];
}

- (void)registerCell
{
    [self.tableView registerNib:[UINib nibWithNibName:SettingCellReuseId bundle:nil] forCellReuseIdentifier:SettingCellReuseId];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return 1;
}

- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath { 
    SettingCell *cell = [tableView dequeueReusableCellWithIdentifier:SettingCellReuseId forIndexPath:indexPath]; 
    cell.titleLb.text = @"更换手机号";
    cell.detailLb.text = [[[NSUserDefaults standardUserDefaults] objectForKey:AppUserPhone] stringByReplacingCharactersInRange:NSMakeRange(3,4) withString:@"****"];
    cell.rightIV.hidden = YES;
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 45.0f;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 10)];
    view.backgroundColor = WB_RGBColor(240, 240, 240);
    return view;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 100)];
    view.backgroundColor = WB_RGBColor(240, 240, 240);
    
    //确定
    UIButton *sureBtn = [Factory customButtonWithTitle:@"更换手机号"];
    sureBtn.frame = CGRectMake(50, 30, kScreenWidth - 100, 60);
    [sureBtn addTarget:self action:@selector(clickMethod:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:sureBtn];
    
    //提示
    UILabel *tipLb = [[UILabel alloc] initWithFrame:CGRectMake(0, sureBtn.mm_bottom + 5, kScreenWidth, 20)];
    tipLb.text = @"一个手机号只能作为一个账号的登录";
    tipLb.textAlignment = NSTextAlignmentCenter;
    tipLb.font = [UIFont systemFontOfSize:12];
    tipLb.textColor = WB_RGBColor(153, 153, 153);
    [view addSubview:tipLb];
    
    return view;
}


- (void)clickMethod:(UIButton *)sender
{
    ReplacePhoneViewController *vc =[[ReplacePhoneViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - 懒加载  Lazy Load
- (UITableView *)tableView
{
    if (_tableView == nil) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - kTabbarHeight) style:UITableViewStyleGrouped];
        _tableView.backgroundColor = WB_RGBColor(240, 240, 240);;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.tableFooterView = [UIView new];
        _tableView.sectionFooterHeight = 100.f;
        _tableView.sectionHeaderHeight = 10.f;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _tableView;
}

@end
